use "C:\Users\mmousseau\Documents\Ifolder\CINE Data\raw for replication.dta", clear

*data sources:
*Beck, Thorsten, and Ian Webb. 2003. "Economic, Demographic, and Institutional Determinants of Life Insurance Consumption across Countries." World Bank Economic Review 17(1): 51-88.
*Euromonitor (2003) �Global Market Information Database.� (available at http://www.euromonitor.com/databases.aspx).
*Fearon, J. D., and D. Laitin. 2003. �Ethnicity, Insurgency, and Civil War.� American Political Science Review 97(1): 75-89.
*Heston, Alan, Robert Summers, and Bettina Aten. 2002. Penn World Table, Ver. 6.2, Philadelphia: Center for International Comparisons of Production, Income, and Prices, University of Pennsylvania.
*World Bank. 2010. World Development Indicators & Global Development Finance. World Bank.


replace 	rgdpl=.	 	 if 	rgdpl	 ==	-99
replace 	openk=.		 if 	openk	 ==	-99
replace 	kc=.	 	 if 	kc	 	 ==	-99
replace 	kg=.	 	 if 	kg		 ==	-99
replace 	ki=.		 if 	ki		 ==	-99
replace 	energy=.	 if 	energy	 ==	-9
replace 	tpop=.		 if 	tpop	 ==	-9


*apparent errors in the data; nations in major transitions:
replace ki=. if ccode==315 & year==1992 | ccode==365 & year==1990 | ccode==365 & year==1991 |  ccode==366 & year==1991 | ccode==690 & year==1991
replace kc=. if ccode==690 & year==1991
replace kg=. if ccode==690 & year==1991
replace openk=. if ccode==690 & year==1991

************
g CIE = ln(lifedeer+1)
drop lifedeer


rename kc kcpct
rename ki kipct
rename kg kgpct
rename openk ktpct
g kc=(kcpct/100)*rgdpl
g ki=(kipct/100)*rgdpl
g kg=(kgpct/100)*rgdpl
g kt=(ktpct/100)*rgdpl
g kitokt=ki/kt
g kctokt=kc/kt

g lnrgdpl=ln(rgdpl)
drop rgdpl
g lnfood=ln(food)
g enrpc=energy/tpop
g lnenrpc=ln(enrpc+1)
drop energy

g imputed=0
replace imputed=1 if CIE==.

recode region1 (1=1 "West") 		(2/5=0 "Other") 				(.=.), gen(rwest)
recode region1 (2=1 "Middle East") (1=0 "Other") 	(3/5=0 "Other") (.=.), gen(rmideast)
recode region1 (3=1 "Africa") 		(1/2=0 "Other") (4/5=0 "Other") (.=.), gen(rafrica)
recode region1 (4=1 "Asia") 		(1/3=0 "Other") (5=0 "Other")   (.=.), gen(rasia)
recode region1 (5=1 "America") 	(1/4=0 "Other") 				(.=.), gen(rameri)
drop region1

g cmmst=0
replace cmmst =1 if year < 1992 & (ccode == 339  | ccode == 345  | ccode == 355  | ccode == 710  | ccode == 40  | ccode ==315  | ccode == 265 | ccode == 310  | ccode == 812  | ccode == 712  | ccode == 731  | ccode == 290 | ccode == 360 | ccode == 365 | ccode == 816)
replace cmmst=1 if ccode==731

g pcom=0		
replace pcom=1 if year >1991 & (ccode== 40 |ccode== 290 |ccode== 310 |ccode== 316 |ccode== 317 |ccode== 331 |ccode== 338 |ccode== 339 |ccode== 343 |ccode== 344 |ccode== 345 |ccode== 346 |ccode== 349 |ccode== 355 |ccode== 359 |ccode== 360 |ccode== 365 |ccode== 366 |ccode== 367 |ccode== 368 |ccode== 369 |ccode== 370 |ccode== 371 |ccode== 372 |ccode== 373 |ccode== 700 |ccode== 701 |ccode== 702 |ccode== 703 |ccode== 704 |ccode== 705 |ccode== 710 |ccode== 712 |ccode== 812 |ccode== 816) 

g micro=0
replace micro=ln(0-tpop+1001) if tpop<1000
replace micro=. if tpop==.

g y7980=0
g y8185=0
g y86=0
g y8791=0
g y92=0
g y9398=0
g y9900=0
replace y7980=1 	if year >=1979 & year<=1980
replace y8185=1 	if year >=1981 & year<=1985
replace y86=1 		if year >=1986 & year<=1986
replace y8791=1 	if year >=1987 & year<=1991
replace y92=1 		if year >=1992 & year<=1992
replace y9398=1 	if year >=1993 & year<=1998
replace y9900=1 	if year >=1999 & year<=2000

g       num6069=1959
replace num6069=year 	if year>=1960 & year <1970
g       num7174=1970
replace num7174=year 	if year>=1971 & year==1974
g       num7583=1974
replace num7583=year 	if year>=1975 & year<=1983
g       num8488=0
replace num8488=1 		if year>=1984 & year<=1988
g       num89=0
replace num89=1 		if year==1989
g       num9091=0 	
replace num9091=1 		if year==1990
replace num9091=2 		if year==1991
g       num92=0 	
replace num92=1 		if year==1992
g       num9394=0
replace num9394=1 		if year==1993
replace num9394=2 		if year==1994
g       num9598=0
replace num9598=1 		if year>=1995 & year<=	1998
g       num99=0
replace num99=1 		if year==1999
g       num00=0
replace num00=1 		if year==2000


keep if ki~=. | CIE~=. | cmmst==1

*BINARY MEASURE:

*hist CIE, bin(100) norm percent
sum CIE, d
* 50%     4.173022
g CIEd=0
replace CIEd=1 if CIE>=4.173022 & CIE~=.
*sort ccode year
*g tst=1 if ccode==ccode[_n+1] & CIEd==1 & CIEd[_n+1]==0
*drop if tst==.
*Smoothing CIEd
replace CIEd=0 if ccode==95  & year==1986
replace CIEd=1 if ccode==666 & year==1985
replace CIEd=1 if ccode==349 & year==1998

*imputations based on the continuous data below; imputed data indicate that Ireland and South Africa probably transitioned about when they entered the data in 1979:
replace CIEd=1 if year>=1999 & ccode==205 | year >=1999 & ccode==210| year >=1999 & ccode==211| year >=1999 & ccode==220| year >=1999 & ccode==230| year >=1999 & ccode==235| year >=1999 & ccode==255| year >=1999 & ccode==305| year >=1999 & ccode==325| year >=1999 & ccode==375
replace CIEd=1 if ccode==920
replace CIEd=1 if ccode==210


*CONTINUOUS MEASURE:

impute CIE enrpc lnenrpc ki kc kitokt kctokt oil pcom cmmst tpop micro rmideast year y7980 y8185 y86 y8791 y92 y9398 y9900 num6069 num7174 num7583 num8488 num89 num9091 num9394 num9598 num99 num00, g (iCIE)
replace iCIE=0 if iCIE<0
*(675 real changes made)
replace CIE=iCIE if CIE==.
* (4245 real changes made)
drop iCIE

*dropping of odd estimates in microstates
replace CIE = . if imputed==1 & tpop <500
* (657 real changes made, 657 to missing)
replace CIEd = . if imputed==1 & tpop <500
* (657 real changes made, 657 to missing)
replace imputed=. if CIE==.

g tCIE=CIE
replace tCIE=. if imputed==0
impute tCIE enrpc lnenrpc ki kc kitokt kctokt oil pcom cmmst tpop micro rmideast year y7980 y8185 y86 y8791 y92 y9398 y9900 num6069 num7174 num7583 num8488 num89 num9091 num9394 num9598 num99 num00, g(ttCIE)
* 30.29% (1546) observations imputed
corr CIE ttCIE
*0.97
drop tCIE

hist CIE, bin(100) norm percent
sum CIE

save "C:\Users\mmousseau\Documents\Ifolder\CINE Data\analyses.dta", replace
use "C:\Users\mmousseau\Documents\Ifolder\CINE Data\analyses.dta", clear
keep ccode year CIE imputed CIEd
rename CIEd CIEbinary
label variable ccode `"COW Country Code"'
label variable year `"Year "'
label variable CIE `"Contract-Intensive Economy"'
label variable imputed `"Indicates imputed values in CIE"'
label variable CIEbinary `"CIE binary"'

save "C:\Users\mmousseau\Documents\Ifolder\CINE Data\CINE 2011.2.15.dta", replace
